package com.ruoyi.wms.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.utils.MapstructUtils;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.wms.domain.bo.employee.PSalarySetupBo;
import com.ruoyi.wms.domain.entity.employee.PSalarySetup;
import com.ruoyi.wms.domain.vo.PSalarySetupVo;
import com.ruoyi.wms.mapper.PSalarySetupMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 绩效等级设置Service业务层处理
 *
 * @author 邓滔滔
 * @date 2024-12-01
 */
@RequiredArgsConstructor
@Service
public class PSalarySetupService {

    private final PSalarySetupMapper pSalarySetupMapper;

    /**
     * 查询绩效等级设置
     */
    public PSalarySetupVo queryById(Long id){
        return pSalarySetupMapper.selectVoById(id);
    }

    /**
     * 查询绩效等级设置列表
     */
    public TableDataInfo<PSalarySetupVo> queryPageList(PSalarySetupBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<PSalarySetup> lqw = buildQueryWrapper(bo);
        Page<PSalarySetupVo> result = pSalarySetupMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询绩效等级设置列表
     */
    public List<PSalarySetupVo> queryList(PSalarySetupBo bo) {
        LambdaQueryWrapper<PSalarySetup> lqw = buildQueryWrapper(bo);
        return pSalarySetupMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<PSalarySetup> buildQueryWrapper(PSalarySetupBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<PSalarySetup> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getLevel() != null, PSalarySetup::getLevel, bo.getLevel());
        return lqw;
    }

    /**
     * 新增绩效等级设置
     */
    public void insertByBo(PSalarySetupBo bo) {
        PSalarySetup add = MapstructUtils.convert(bo, PSalarySetup.class);
        pSalarySetupMapper.insert(add);
    }

    /**
     * 修改绩效等级设置
     */
    public void updateByBo(PSalarySetupBo bo) {
        PSalarySetup update = MapstructUtils.convert(bo, PSalarySetup.class);
        pSalarySetupMapper.updateById(update);
    }

    /**
     * 批量删除绩效等级设置
     */
    public void deleteByIds(Collection<Long> ids) {
        pSalarySetupMapper.deleteBatchIds(ids);
    }
}
